<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计算器</title>
	</head>
	<body>
		请输入第一个运算数：<input type="text" name="" id="addent1" value="" /><br/>
		请输入第二个运算数：<input type="text" name="" id="addent2" value="" /><br/>
		请选择运算法则：<select id="algorithm">
			<option value ="">加</option>
			<option value ="">减</option>
			<option value ="">乘</option>
			<option value ="">除</option>
			<option value ="">模</option>
		</select>
		<button type="button" id="count">计算</button><br/>
		运算结果是：<span id="result"></span>
		
		<script type="text/javascript">

			
			 var count=document.getElementById("count");
			 var result=document.getElementById("result");
			 count.onclick=function(){
				 var addent_one=document.getElementById("addent1");//获取第一个数
				 var addent_two=document.getElementById("addent2");//获取第二个数
				 
				 var Algorithm=document.getElementById("algorithm");//1.找到对象
				 var index=Algorithm.selectedIndex;//2.获取选项索引
				 var algorithm1=Algorithm.options[index].text;//3.获取选项值
				 switch(algorithm1){
					 case "加":
								result.innerHTML=Number(addent_one.value)+Number(addent_two.value);break;
					case "减":
								result.innerHTML=Number(addent_one.value)-Number(addent_two.value);break;
					case "乘":
							result.innerHTML=Number(addent_one.value)*Number(addent_two.value);break;
					case "除":
								result.innerHTML=Number(addent_one.value)/Number(addent_two.value);break;
					case "模":
								result.innerHTML=Number(addent_one.value)%Number(addent_two.value);break;
				 default://多余选项，用于运算法则被修改时
						result.innerHTML="非法运算";
				 }
				 
			 }
			
			
		</script>
	</body>
</html>
